import React, { useEffect, useState } from 'react';
import {
    Button,
    Cascader,
    DatePicker,
    Form,
    Input,
    InputNumber,
    Radio,
    Select,
    Switch,
    TreeSelect,
} from 'antd';
import type { FormProps } from 'antd';
import { addLyh,patchLyh } from '@/app/axios/http';
type SizeType = Parameters<typeof Form>[0]['size'];
type FieldType = {
    username?: string;
    password?: string;
    remember?: string;
};
const MyForm: React.FC = (props) => {
    useEffect(() => {
        if (props.name == "编辑用户") {
            form.setFieldsValue(props.list)
        }
    }, [])
    const [form] = Form.useForm();
    const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
        if (props.name == "添加客户") {
            let obj = {
                ...values,
                yprice: 1535180040000,
                id: new Date().getTime()
            }
            addLyh(obj).then(res => {
                props.handleOk()
                props.mm()
            })
        }else{
            let obj={
                ...props.list,
                ...values,
            }
            console.log(obj.id)
            patchLyh(obj).then(res=>{
                props.handleOk()
                props.mm()
            })
        }

    };

    return (
        <Form

            layout="horizontal"
            form={form}
            onFinish={onFinish}
            style={{ maxWidth: 600 }}
        >

            <Form.Item label="客户名称" name='key' rules={[{ required: true, message: '客户名称不能为空' }]}>
                <Input />
            </Form.Item>
            <Form.Item label="客户状态" name='name' rules={[{ required: true, message: '请选择跟进状态' }]}>
                <Select>
                    <Select.Option value="没有跟进">没有跟进</Select.Option>
                    <Select.Option value="正在跟进">正在跟进</Select.Option>
                </Select>
            </Form.Item>
            <Form.Item label="客户星级" name='kehu' rules={[{ required: true, message: '请选择客户星级' }]}>
                <Select>
                    <Select.Option value="一星">一星</Select.Option>
                    <Select.Option value="二星">二星</Select.Option>
                    <Select.Option value="三星">三星</Select.Option>
                    <Select.Option value="四星">四星</Select.Option>
                    <Select.Option value="五星">五星</Select.Option>
                </Select>
            </Form.Item>
            <Form.Item label="首联系人" name='Collor' rules={[{ required: true, message: '请输入首联系人' }]}>
                <Input />
            </Form.Item>
            <Form.Item label="手机号码" name='price' rules={[{ required: true, message: '请输入手机号' }]}>
                <Input />
            </Form.Item>
            <Form.Item label="未跟进天数" name='kprice' rules={[{ required: true, message: '请输入未跟进天数' }]}>
                <InputNumber />
            </Form.Item>
            <Button htmlType="submit">确定</Button>
        </Form>
    );
};

export default MyForm;
